﻿using Dapper_Core.Model;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dapper_Core.Model
{
    public static class Appsettings
    {
        private static string _sessionType;
        public static string SessionType { get { return _sessionType; } }

        private static DBConnection _sqlServerConnection01;
        public static DBConnection SqlServerConnection01 { get { return _sqlServerConnection01; } }

        private static DBConnection _mySqlConnection01;
        public static DBConnection MySqlConnection01 { get { return _mySqlConnection01; } }

        private static string _databaseType;
        public static string DatabaseType { get { return _databaseType; } }

        private static string _deployType;
        public static string DeployType { get { return _deployType; } }

        private static string _uEditorFileServer;
        public static string UEditorFileServer { get { return _uEditorFileServer; } }

        private static RedisServer _redisServer;
        public static RedisServer RedisServer { get { return _redisServer; } }

        #region 邮箱相关参数
        private static string _smtpServer = "smtp.h3c.com";
        /// <summary>
        /// 邮箱服务地址，默认是smtp.h3c.com
        /// </summary>
        public static string SmtpServer { get { return _smtpServer; } }

        private static int _smtpPort = 25;
        /// <summary>
        /// 邮箱服务端口号，默认是25
        /// </summary>
        public static int SmtpPort { get { return _smtpPort; } }

        private static string _smtpAccountID;
        /// <summary>
        /// 邮箱服务服务账户
        /// </summary>
        public static string SmtpAccountID { get { return _smtpAccountID; } }

        private static string _smtpAccountPassword;
        /// <summary>
        /// 邮箱服务服务账户密码
        /// </summary>
        public static string SmtpAccountPassword { get { return _smtpAccountPassword; } }

        private static string _mailSender = "ADMP@h3c.com";
        /// <summary>
        /// ADMP提醒邮件的发送者，默认是ADMP@h3c.com
        /// </summary>
        public static string MailSender { get { return _mailSender; } }
        #endregion

        private static string _alipayAppId;
        public static string AlipayAppId { get { return _alipayAppId; } }
        private static string _alipayMerchantPrivateKey;
        public static string AlipayMerchantPrivateKey { get { return _alipayMerchantPrivateKey; } }
        private static string _alipayPublicKey;
        public static string AlipayPublicKey { get { return _alipayPublicKey; } }

        private static string _wechatAppId;
        public static string WechatAppId { get { return _wechatAppId; } }
        private static string _wechatMerchant;
        public static string WechatMerchant { get { return _wechatMerchant; } }
        private static string _wechatPartnerKey;
        public static string WechatPartnerKey { get { return _wechatPartnerKey; } }
        private static string _wechatNotifyUrl;
        public static string WechatNotifyUrl { get { return _wechatNotifyUrl; } }

        private static string _jsAPIAppId;
        public static string JSAPIAppId { get { return _jsAPIAppId; } }
        private static string _jsAPIAppSecret;
        public static string JSAPIAppSecret { get { return _jsAPIAppSecret; } }

        /// <summary>
        /// 初始化json文件中的配置项
        /// </summary>
        /// <param name="configuration"></param>
        public static void Initial(IConfiguration configuration)
        {
            _databaseType = configuration["DatabaseType"];

            _deployType = configuration["DeployType"];

            _sessionType = configuration["SessionType"];

            _sqlServerConnection01 = new DBConnection();
            _sqlServerConnection01.Value = configuration["SqlServerConnection01:Value"];
            _sqlServerConnection01.ProviderName = configuration["SqlServerConnection01:ProviderName"];

            _mySqlConnection01 = new DBConnection();
            _mySqlConnection01.Value = configuration["MySqlConnection01:Value"];
            _mySqlConnection01.ProviderName = configuration["MySqlConnection01:ProviderName"];

            _uEditorFileServer = configuration["UEditorFileServer"];

            #region 初始化邮箱相关参数
            if (!string.IsNullOrEmpty(configuration["SmtpServer"]))
            {
                _smtpServer = configuration["SmtpServer"];
            }
            else
            {
                _smtpServer = "smtp.h3c.com";
            }

            try
            {
                _smtpPort = Convert.ToInt32(configuration["SmtpPort"]);
            }
            catch (Exception ex)
            {
                _smtpPort = 25;
            }

            _smtpAccountID = configuration["SmtpAccountID"];

            _smtpAccountPassword = configuration["SmtpAccountPassword"];

            if (!string.IsNullOrEmpty(configuration["MailSender"]))
            {
                _mailSender = configuration["MailSender"];
            }
            else
            {
                _mailSender = "ADMP@h3c.com";
            }
            #endregion

            _redisServer = new RedisServer();
            _redisServer.Type = configuration["RedisServer:Type"];
            _redisServer.Host = configuration["RedisServer:Host"];
            _redisServer.Password = configuration["RedisServer:Password"];
            _redisServer.CustomKey = configuration["RedisServer:CustomKey"];
            _redisServer.ClusterNodes = (configuration["RedisServer:ClusterNodes"] ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            _alipayAppId = configuration["Alipay.AppId"];
            _alipayMerchantPrivateKey = configuration["Alipay.MerchantPrivateKey"];
            _alipayPublicKey = configuration["Alipay.PublicKey"];

            _wechatAppId = configuration["Wechat.AppId"];
            _wechatMerchant = configuration["Wechat.Merchant"];
            _wechatPartnerKey = configuration["Wechat.PartnerKey"];
            _wechatNotifyUrl = configuration["Wechat.NotifyUrl"];

            _jsAPIAppId = configuration["JSAPI.AppId"];
            _jsAPIAppSecret = configuration["JSAPI.AppSecret"];
        }
    }
}
